import format from '@dfeidao/atom-web/dt/format';
import parse from '@dfeidao/atom-web/dt/parse';
import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import get from '@dfeidao/atom-web/local/get';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
import Paging from "@dfeidao/fd-w000010";
import p001 from './p001';
export default async function a001(fd: IFeidaoAiBrowserComponent, a: { page_no: number }) {

	const asc = get(fd, 'asc');
	const desc = get(fd, 'desc');


	const p = a.page_no;
	const pageno = Number(p) || 1;
	const name = fd.data.node.querySelector<HTMLInputElement>('[data-id="name"]').value;
	const starttime = fd.data.node.querySelector<HTMLInputElement>('[data-id="starttime"]').value || '1970-01-01';
	const endtime = fd.data.node.querySelector<HTMLInputElement>('[data-id="endtime"]').value || '3000-01-01';
	const t1 = parse(starttime);
	const t2 = parse(endtime);
	if (t1 > t2) {
		alert("结束时间应大于开始时间");
		return;
	}

	const r = await nodejs<{ data: Array<{ record_no: string, plan_no: string, plan_name: string, record_location: string, inspection_time: string }>, n: number }>('imple-records/zj-000004/s001', {
		filter: {
			plan_name: name,
			starttime,
			endtime,
			pageno,
			asc,
			desc
		}
	});

	r.data.map((v2) => {
		v2.inspection_time = format(Number(v2.inspection_time), 0);
	});

	render(fd, r, p001, 'p001', 'inner');
	// 引入控件包 转换为控件类型
	const paging = fd.data.node.querySelector<Paging>('[data-id="paging"]');
	if (paging) {
		paging.setAttribute('page-no', pageno + '');
	}

}
